package customfields;

import log.Logger;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import beans.Notification;

public class NotificationField extends Field{
	
	//private String date;
	private String text;
	private int textColor;
	private int textColorUnfocused = Color.BLACK;
	private int textColorFocused = Color.WHITE;
	private int height = (int) (getFont().getHeight());
	private int width = (int) (Display.getWidth()*0.95);
	
	public NotificationField(Notification n){
		super(Field.FOCUSABLE | Field.FIELD_HCENTER);
		this.text=n.getText();
	}
	
	public int getPreferredWidth() {  
		return width;  
	}  

	public int getPreferredHeight() {  
		return height;  
	}  

	protected void onFocus(int direction) {
		textColor = textColorFocused; 
		invalidate();  
	}  

	protected void onUnfocus() {  
		textColor = textColorUnfocused;  
		invalidate();  
	} 

	protected void layout(int arg0, int arg1) {
		setExtent(getPreferredWidth(), getPreferredHeight());  
	}

	protected void paint(Graphics graphics) {
		graphics.setColor(textColor);
		graphics.drawText(text, 10, 0);
	}
	
	protected void fieldChangeNotify(int context) {
		try {
			this.getChangeListener().fieldChanged(this, context);
		}
		catch (Exception e) {
			Logger.log("field error");
		}
	}


	protected boolean navigationClick(int status, int time) {
		fieldChangeNotify(1);
		return true;
	}


}
